#include "HistoryManager.h"
#include "EventDispatcher.h"

HistoryManager* HistoryManager::singleton = NULL;

HistoryManager* HistoryManager::instance()
{
	if (HistoryManager::singleton == NULL)
	{
		HistoryManager::singleton = new HistoryManager();
	}

	return HistoryManager::singleton;
}

void HistoryManager::addHistoryEvent(HistoryEvent* _event)
{
	this->events.push_back(_event);
}


void HistoryManager::revertToEvent(HistoryEvent* _event)
{

	Event* currentEvent;
	do
	{
		if (!this->events.empty())
		{
			currentEvent = this->events.back();
			currentEvent->owner->reverseEvent(currentEvent);
			this->events.pop_back();
		}
	}
	while (currentEvent != _event);
}
